package org.jeecg.modules.friends.dao.impl;

import java.util.List;

import org.jeecg.modules.friends.condition.SchoolMetaDataCondition;
import org.jeecg.modules.friends.mapper.ext.SchoolMetaDataDOExtMapper;
import org.jeecg.modules.friends.metainfo.param.SchoolListQueryParam;
import org.jeecg.modules.friends.model.SchoolMetaDataDO;
import org.parboiled.common.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SchoolMetaDataDAOImpl implements org.jeecg.modules.friends.dao.SchoolMetaDataDAO {
    @Autowired
    private SchoolMetaDataDOExtMapper schoolMetaDataDOExtMapper;

    @Override
    public List<SchoolMetaDataDO> getSchoolMetaDataDOS(SchoolListQueryParam queryParam) {
        SchoolMetaDataCondition condition = new SchoolMetaDataCondition();
        SchoolMetaDataCondition.Criteria criteria = condition.createCriteria();
        if (StringUtils.isNotEmpty(queryParam.getSchoolName())){
            criteria.andSchoolNameLike("%" + queryParam.getSchoolName() + "%");
        }
        int start = (queryParam.getPageNo() - 1 ) * queryParam.getPageSize();
        condition.setOffset(start);
        condition.setLimit(queryParam.getPageSize());
        return schoolMetaDataDOExtMapper.selectByCondition(condition);
    }

    @Override
    public Long countByParam(SchoolListQueryParam queryParam) {
        SchoolMetaDataCondition condition = new SchoolMetaDataCondition();
        SchoolMetaDataCondition.Criteria criteria = condition.createCriteria();
        if (StringUtils.isNotEmpty(queryParam.getSchoolName())){
            criteria.andSchoolNameLike("%" + queryParam.getSchoolName() + "%");
        }
        return schoolMetaDataDOExtMapper.countByCondition(condition);
    }
}